﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Workflows.Components.TextMining.Clustering
{
    public delegate void ExcludedTermsUpdated(List<string> excludedTerms);

    public partial class ExcludedTermsEditor : Form
    {
        public event ExcludedTermsUpdated OnExcludedTermsUpdated;

        public ExcludedTermsEditor()
        {
            InitializeComponent();
        }

        private void ExcludedTermsEditor_Load(object sender, EventArgs e)
        {

        }

        public List<string> ExcludedTerms
        {
            set
            {
                this.dv_ExcludedTerms.Rows.Clear();
                if(value !=null && value.Count>0)
                {
                    foreach(string exTerm in value)
                    {
                        DataGridViewRow dr =new DataGridViewRow();
                        DataGridViewTextBoxCell cellExTerm=new DataGridViewTextBoxCell();
                        cellExTerm.Value = exTerm;
                        dr.Cells.Add(cellExTerm);
                        this.dv_ExcludedTerms.Rows.Add(dr);
                    }
                }
            }
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            List<string> exTerms = new List<string>();
            foreach(DataGridViewRow dr in this.dv_ExcludedTerms.Rows)
            {
                if(!dr.IsNewRow && dr.Cells[0].Value !=null)
                {
                    string exTerm = (string) dr.Cells[0].Value;
                    if(!string.IsNullOrEmpty(exTerm))
                    {
                        exTerms.Add(exTerm);
                    }
                }
            }

            if(this.OnExcludedTermsUpdated !=null)
            {
                this.OnExcludedTermsUpdated(exTerms);
            }

            this.Close();
        }
    }
}
